export default{
        // 评论
    getcomment(i) {
        if (this.comment == "") {
          console.log(111);
        } else {
          let user_id = localStorage.getItem("uid");
          console.log(user_id);
          this.$http.post("/api/add_comment", {
              user_id: user_id,
              article_id: this.id||this.article_id,
              comment_type: i,
              reply_comment_id:this.item._id,
              content: this.comment,
            })
            .then((res) => {
              // 更新评论
              if (i) {
                if (res.code == 0) {
                  console.log(res);
                  this.$toast.success(res.msg);
                  let{avatar,nickname,username}=JSON.parse(localStorage.getItem('userInfo'))
                  // console.log(avatar,nickname,username);
                  let commentData={
                    info:{
                      avatar,
                      nickname,
                      username,
                    },
                    create_time:new Date().getTime(),
                    content:this.comment,
                    reply_num:0,
                    is_like:false,
                    like_count:0,
                    _id:res.data.id
                  }
                  // console.log(commentData);
                  this.evaluate.unshift(commentData)
                  this.loading+=1
                  this.comment = "";
                }
              } else {
                if (res.code == 0) {
                  console.log(res);
                  this.$toast.success(res.msg);
                  // 重新调接口  
                  // this.getevaluate() 

                  // 凭接假数据
                  let{avatar,nickname,username}=JSON.parse(localStorage.getItem('userInfo'))
                  // console.log(avatar,nickname,username);
                  let commentData={
                    info:{
                      avatar,
                      nickname,
                      username,
                    },
                    create_time:new Date().getTime(),
                    content:this.comment,
                    reply_num:0,
                    is_like:false,
                    like_count:0,
                    _id:res.data.id
                  }
                  // console.log(commentData);
                  this.evaluate.unshift(commentData)
                  this.loading+=1
                  this.comment = "";
                  this.goback()
                }
              }
            });
        }
    },
    // 评论点赞
    comments(is_like, id,shuzu) {
        console.log(is_like, id,shuzu);
        let user_id = localStorage.getItem("uid");
        if (!is_like) {
          this.$http
            .post("/api/comment_like", {
              user_id,
              comment_id: id,
            })
            .then((res) => {
              console.log(res);
              if (res.code == 0) {
                shuzu.is_like = true;
                shuzu.like_count += 1;
                this.$toast(res.msg);
              }
            });
        } else {
          this.$http
            .post("/api/comment_unlike", {
              user_id,
              comment_id: id,
            })
            .then((res) => {
              console.log(res);
              if (res.code == 0) {
                shuzu.is_like = false;
                shuzu.like_count -= 1;
                this.$toast(res.msg);
              }
            });
        }
    },
    
}